//
// Copyright (C) 2020-2021 IOTech Ltd
//
// SPDX-License-Identifier: Apache-2.0

package dtos

import (
	"github.com/edgexfoundry/edgex-go/internal/app/models"
	models2 "github.com/edgexfoundry/edgex-go/internal/app/models"
	"github.com/edgexfoundry/go-mod-core-contracts/v2/dtos"
)

// Device and its properties are defined in the APIv2 specification:
// https://app.swaggerhub.com/apis-docs/EdgeXFoundry1/core-metadata/2.1.0#/Device
type ProductCategory struct {
	dtos.DBTimestamp `json:",inline"`
	Id               string `json:"id,omitempty" validate:"omitempty,uuid"`
	Name             string `json:"name"`
	Order            string `json:"order"`
	Description      string `json:"description"`
}

// UpdateDevice and its properties are defined in the APIv2 specification:
// https://app.swaggerhub.com/apis-docs/EdgeXFoundry1/core-metadata/2.1.0#/UpdateDevice
type UpdateProductCategory struct {
	Id          *string `json:"id" validate:"required_without=Name,edgex-dto-uuid"`
	Name        *string `json:"name"`
	Order       *string `json:"order"`
	Description *string `json:"description"`
}

// ToProductCategoryModel transforms the ProductCategoryModel DTO to the ProductCategory Model
func ToProductCategoryModel(dto ProductCategory) models2.ProductCategory {
	var d models2.ProductCategory
	d.Id = dto.Id
	d.Name = dto.Name
	d.Order = dto.Order
	d.Description = dto.Description
	return d
}

// FromProductCategoryModelToUpdateDTO transforms the ProductCategory Model to the UpdateProductCategory DTO
func FromProductCategoryModelToUpdateDTO(d models2.ProductCategory) UpdateProductCategory {
	dto := UpdateProductCategory{
		Id:          &d.Id,
		Name:        &d.Name,
		Description: &d.Description,
		Order:       &d.Order,
	}
	return dto
}

// FromProductCategoryModelToDTO transforms the ProductCategory Model to the ProductCategory DTO
func FromProductCategoryModelToDTO(d models.ProductCategory) ProductCategory {
	var dto ProductCategory
	dto.DBTimestamp = dtos.DBTimestamp(d.DBTimestamp)
	dto.Id = d.Id
	dto.Name = d.Name
	dto.Description = d.Description
	dto.Order = d.Order

	return dto
}
